USE AdventureWorks2008

--Create a trigger
CREATE TRIGGER trigCurrency 
   ON  Sales.Currency 
   AFTER INSERT
AS 
BEGIN
	DECLARE @name nvarchar(50)
	SELECT @name = Name
	FROM inserted
	IF len(@name) < 5 
	BEGIN
		ROLLBACK TRANSACTION
	END
END

GO

--See the results of a trigger
--This statement will fail: 
	INSERT INTO Sales.Currency(CurrencyCode, Name) VALUES('BAD', 'BAD')

--This statement will succeed:
	INSERT INTO Sales.Currency(CurrencyCode, Name) VALUES('YES', 'THIS IS GOOD')
